#define cpuid(in, a, b, c, d) __asm__("cpuid": "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (in));

typedef 
  struct 
    { 
      unsigned short length;
      unsigned long base;
    } __attribute__((__packed__)) 
    IDTR;
static inline unsigned read_cr0() {
   unsigned val;
   asm volatile("mov %%cr0, %0":"=r"(val));
   return val;
}

static inline unsigned read_cr2() {
   unsigned val;
   asm volatile("mov %%cr2, %0":"=r"(val));
   return val;
}

static inline unsigned read_cr3() 
{
  unsigned val;
  asm volatile("mov %%cr3, %0":"=r"(val));
  return val;
}

static inline void write_cr0(u32 val)
{
  asm volatile("mov %%eax, %%cr0":"a"(val))
}

void lidt(void *base, unsigned short size) 
{

  IDTR.length = size;
  IDTR.base = (unsigned long) base;
  asm ("lidt (%0)": :"p" (&IDTR));
}
